package drawing
{
	import flash.display.BitmapData;
	import flash.display.Graphics;
	import furnitures.FurnitureModel;
	import resources.Images;
	import utils.Logger;
	
	/**
	 * ...
	 * @author Dmitriy Gaiduk
	 */
	public class BitmapPalette implements IPaletteDisposable
	{
		private var _texture:BitmapData;
		private var _repeatBitmap:Boolean = true;
		private var _smooth:Boolean = true;
		private var _glassColor:uint = 0xCCFFF4;
		
		public function BitmapPalette(texture:BitmapData)
		{
			_texture = texture;
		}
		
		/* INTERFACE draw.IPalette */
		
		public function beginFill(surface:Graphics, brushType:String, 
									surfaceWidth:Number, 
									surfaceHeight:Number,
									reverseByX:Boolean = false,
									reverseByY:Boolean = false):Boolean
		{
			var fillTexture:BitmapData;
			switch(brushType) {
				case FurnitureModel.EXTRA_GRID:
						fillTexture = Images.getImageBitmap(Images.GRID);
					break;
				case FurnitureModel.EXTRA_GLASS:
						fillTexture = Images.getImageBitmap(Images.GLASS);
					break;
				default:
						fillTexture = _texture;
					break;
			}
			
			if (fillTexture != null) {
				surface.lineStyle(3, 0x000000);
				surface.beginBitmapFill(fillTexture, null, _repeatBitmap, _smooth);
				return true;
			}else {
				return false;
			}
		}
		
		public function endFill(surface:Graphics):void 
		{
			surface.endFill();
		}
		
		public function lineStyle(surface:Graphics):Boolean
		{
			return false;
		}
		
		
		public function get repeatBitmap():Boolean 
		{
			return _repeatBitmap;
		}
		
		public function set repeatBitmap(value:Boolean):void 
		{
			_repeatBitmap = value;
		}
		
		public function get smooth():Boolean 
		{
			return _smooth;
		}
		
		public function set smooth(value:Boolean):void 
		{
			_smooth = value;
		}
		
		public function get glassColor():uint 
		{
			return _glassColor;
		}
		
		public function set glassColor(value:uint):void 
		{
			_glassColor = value;
		}
		
		public function get texture():BitmapData 
		{
			return _texture;
		}
		
		public function set texture(value:BitmapData):void 
		{
			_texture = value;
		}
		
		/* INTERFACE draw.IPaletteDisposable */
		
		public function dispose():void 
		{
			log("Dispose texture");
			if (_texture != null)
			{
				_texture.dispose();
			}
			_texture = null;
		}
		
		private function log(msg:String):void
		{
			Logger.log(this, msg);
		}
	
	}

}